package org.vectrics.recruiter.xmlweb;

import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.vectrics.SystemException;
import org.vectrics.calendar.struts.CalendarTag;
import org.vectrics.common.util.StringUtils;
import org.vectrics.dataweb.WebServiceAction;
import org.vectrics.location.Location;
import org.vectrics.location.LocationCriteria;
import org.vectrics.provider.CoreServiceLocator;
import org.vectrics.struts.Request;
import org.vectrics.user.Person;
import org.vectrics.user.PersonEncounter;
import org.vectrics.user.PersonSearchCriteria;
import org.w3c.dom.Element;


public class LocationGetWebService extends WebServiceAction {
	public static String COMMAND = "get.location";
	
	@Override
	public void getData(Request request, String command,
			Element requestElement, Element responseElement) {
		log.info("Command: " + command);
		Element dataElement = this.getDataElement(responseElement);
		Location location = CoreServiceLocator.getLocationService().findLocation(new Long(request.getParameter("locationId")));
		log.info("Location search - found location: " + location);
		Element locationElement = responseElement.getOwnerDocument().createElement("location");

		this.locationToElement(location, locationElement);
		
		dataElement.appendChild(locationElement);
	}
	
	private void locationToElement(Location location, Element locationElement) {
		locationElement.setAttribute("id", location.getId().toString());
		locationElement.setAttribute("description", location.getDescription());
		locationElement.setAttribute("typeCode", location.getTypeCode());
		locationElement.setAttribute("name", location.getName());
		locationElement.setAttribute("domain", location.getDomain().getId().toString());
	}
}
